<?php

class ReceiveRequestJoinCluster {
	private $message = "";
	private $cm = null;
    function ReceiveRequestJoinCluster() {
    	$this->cm = new ClusterManager();
    }
    
    public function run() {
    		//return $this->message = 1;
    		if($this->cm->autointo!=1) {//没开启则忽略
				$this->message = 2 ;
				return;
			}
    		$cp = $this->cm->cp;
    		$m = $this->getValue($cp->getParamValue('AUTO_ALLOW_MODE'),1);
    		$n = $this->getValue($cp->getParamValue('AUTO_ALLOW_MODE'),2);
    		$k = $this->getValue($cp->getParamValue('AUTO_ALLOW_MODE'),3);
			if($k==1) {
				$blacklist = new Blacklist();
				if ($blacklist->isInBlacklist()) {
					$this->message = "0:黑名单用户~~";
					return;
				}
			}
			
			if($m==0) {
				$this->message = 1;
				return;
			}
			if($m==1) { 
				if(trim($_POST[Message]) == trim($_SESSION['CHECK_CODE']) && trim($_POST[Message])!= "") {
					$this->message = 1 ;
				} else {
					if($n==0)
						$this->message = 2;
					else
						$this->message = "0:加群验证码有误~!" ;
				}
				$_SESSION['CHECK_CODE'] = "";
				return ;
			}
			
			if($m==2) {
				$key = $cp->getParamValue('AUTO_ALLOW_KEY');
				$rows=split(' ',$key);
				$flag = false ;
				if($rows &&count($rows)>0 ) {
					for($i=0;$i<count($rows);$i++) {
						if (@ strpos("yaya".$_POST[Message],$rows[$i])) {
							$flag = true;
							break;
						}
					}
					
				}
				if($flag) {
					$this->message = 1 ;
				} else {
					if($n==0)
						$this->message = 2;
					else
						$this->message = "0:请说明加群理由~~";
				}
			}
		
	}
	private function getValue($str,$index) {
		$v = substr($str,$index-1,1);
		return $v;
	}
	
	private function __get($property_name) {
		return $this-> $property_name;
	}

	private function __set($property_name, $value) {
		$this->$property_name = $value;
	}
}
?>